package com.mall.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mall.bean.Collect;
import com.mall.bean.User;
import com.mall.service.ICollectionService;

@Controller
public class CollectionController {

	@Resource
	private ICollectionService collectionService;


	@RequestMapping("addCollection")
	@ResponseBody
	public Map<String, Object> addCollection(@Param("goods_id") Integer goods_id, Collect collect, HttpSession session) {
		Map<String, Object> resMap = new HashMap<String, Object>();
		User user = (User) session.getAttribute("user");

		collect.setUser_id(user.getUser_id());
		collect.setGoods_id(goods_id);
		boolean is = collectionService.isCollection(collect);
		if (is) {
			resMap.put("exist", "您已加入收藏，请勿重新加购");
			return resMap;
		} else {
			collectionService.addCollection(collect);
			resMap.put("success", "您已成功加入收藏");
			return resMap;
		}
	}

}
